package com.yfp.operation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.MachineDO;
import com.yfp.operation.domain.MachineTempWarnDO;
import com.yfp.operation.domain.dto.WarnParameterDTO;
import com.yfp.operation.domain.vo.MachineErrorVO;
import com.yfp.operation.service.MachineTempWarnService;
import com.yfp.operation.mapper.MachineMapper;
import com.yfp.operation.mapper.MachineTempWarnMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MachineTempWarnServiceImpl extends ServiceImpl<MachineTempWarnMapper, MachineTempWarnDO> implements MachineTempWarnService {

    @Autowired
    private MachineMapper machineMapper;
    @Autowired
    private MachineTempWarnMapper machineTempWarnMapper;

    /**
     * 温度报警
     * @param warnParameterDTO
     * @return
     */
    @Override
    public List<MachineErrorVO> getMachineTempWarn(WarnParameterDTO warnParameterDTO) {

        // 获取设备名称
        MachineDO machine = machineMapper.getMachine(warnParameterDTO.getMachineId());
        // 温度
        List<MachineErrorVO> tempWarnList = machineTempWarnMapper.getMachinTempWarn(warnParameterDTO);
        tempWarnList.forEach(machineError -> {
            machineError.setMachineName(machine.getMachineName());
            machineError.setErrorType(warnParameterDTO.getStatus());
        });

        return tempWarnList;

    }
}
